package com.sl.au.repository;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import com.sl.au.entity.ChanceTrance;

@Transactional(readOnly = true)
public interface ChanceTranceRepository extends JpaRepository<ChanceTrance, String>{

	 /**
	  * 获取分配员工跟踪情况的数据
	  * @param chanceId
	  * @param pageable
	  * @return
	  */
	 @Query("select c from ChanceTrance c where c.saleChance.id =?1 "
	 		+ "and c.user.id =?2")
	 Page<ChanceTrance> findMyTrance(String chanceId, String userId,Pageable pageable);
	 
	 /**
	  * 获取分配员工跟踪情况的数据总条数
	  * @param chanceId
	  * @param pageable
	  * @return
	  */
	 @Query("select count(*) from ChanceTrance c where c.saleChance.id =?1 "
	 		+ "and c.user.id =?2")
	 int findMyTranceCount(String chanceId, String userId);
	 
	 /**
	  * 获取该信息所有分配员工跟踪情况的数据
	  * @param chanceId
	  * @param pageable
	  * @return
	  */
	 @Query("select c from ChanceTrance c where c.saleChance.id =?1 ")
	 Page<ChanceTrance> findAllTrance(String chanceId,Pageable pageable);
	 
	 /**
	  * 获取该信息所有分配员工跟踪情况的数据条数
	  * @param chanceId
	  * @param pageable
	  * @return
	  */
	 @Query("select count(*) from ChanceTrance c where c.saleChance.id =?1 ")
	 int findAllTranceCount(String chanceId);
}
